import openpyxl
from openpyxl.reader.excel import load_workbook

from config.config import *
# EXCEL=EXCEL_PATH,worksheet=WORKSHEET

def read_excel():
    #打开
    workbook=openpyxl.load_workbook(EXCEL_PATH)
    worksheet=workbook[WORKSHEET]
    data=[]
    # 读取
    keys=[cell.value for cell in worksheet[2]]#列表推导式,拿key行，也就是从表的第2行，生成一个key列表
    for row in worksheet.iter_rows(min_row=3,values_only=True):#从第3行开始获取信息，values_only表示只获得值
        a=list(row)
        dic=(dict(zip(keys,a)))#zip函数可以把两个数组变成1个字典对象，dict再将字典对象转化成字典
        if dic["is_true"]:
            data.append(dic)#把字典加入到数组中
    #关闭
    workbook.close()
    return  data


# print(read_excel())
